clear all
set more off

cd "\workfiles"

use step001_QJE_2, clear

format time %tq

keep dprez time dpr  mppr clpr prpr peso

recode dpr (-3 -2 -1 = -1) (0 = 0) (1 2 3 = 1), gen(dpr3)
recode mppr (-3 -2 -1 = -1) (0 = 0) (1 2 3 = 1), gen(mppr3)
recode clpr (-3 -2 -1 = -1) (0 = 0) (1 2 3 = 1), gen(clpr3)
recode prpr (-3 -2 -1 = -1) (0 = 0) (1 2 3 = 1), gen(prpr3)

drop if dpr3 == .
drop if mppr3 == .
drop if clpr3 == .
drop if dprez == .

collapse (mean) dpr3 mppr3 clpr3 prpr3 dprez  [aw = peso], by(time)

gen dpr = dpr3 * 100
gen mppr = mppr3 * 100
gen clpr = clpr3 * 100
gen prpr = prpr3 * 100
  


* Total demand
twoway bar dpr time, yaxis(1) ytitle("") ylabel(-40(10)40) xlabel(184(8)236) fcolor(red) || line dprez t, lwidth(medthick) lcolor(black) yaxis(2) ytitle("", axis(2)) ylabel(0(0.5)3, axis(2)) ///
       legend(pos(2) ring(0) col(1) region(lwidth(none)) order(  1 "Factor: Total demand" 2 "Own-price expected change (RHS)" ) ) ///
	   title("Panel A") ///
	   graphregion(color(white)) bgcolor(white) ///
	   xsize(5) ysize(4) ///
	   	name(fig1, replace)  
		

* Total demand
twoway bar mppr time, yaxis(1) ytitle("") ylabel(-20(20)80) xlabel(184(8)236) fcolor(green) || line dprez t, lwidth(medthick) lcolor(black) yaxis(2) ytitle("", axis(2)) ylabel(0(0.5)3, axis(2)) ///
       legend(pos(2) ring(0) col(1) region(lwidth(none)) order(  1 "Factor: Raw materials prices" 2 "Own-price expected change (RHS)" ) ) ///
	   title("Panel B") ///
	   graphregion(color(white)) bgcolor(white) ///
	     xsize(5) ysize(4) ///
	   	name(fig2, replace) 		
		

* Total demand
twoway bar clpr time, yaxis(1) ytitle("") ylabel(0(10)60) xlabel(184(8)236) fcolor(midblue) || line dprez t, lwidth(medthick) lcolor(black) yaxis(2) ytitle("", axis(2)) ylabel(0(0.5)3, axis(2)) ///
       legend(pos(2) ring(0) col(1) region(lwidth(none)) order(  1 "Factor: Labor costs" 2 "Own-price expected change (RHS)" ) ) ///
	   title("Panel C") ///
	   graphregion(color(white)) bgcolor(white) ///
	     xsize(5) ysize(4) ///
	   	name(fig3, replace) 		
		

* Total demand
twoway bar prpr time, yaxis(1) ytitle("") ylabel(-60(20)40) xlabel(184(8)236) fcolor(gray)  || line dprez t, lwidth(medthick) lcolor(black) yaxis(2) ytitle("", axis(2)) ylabel(0(0.5)3, axis(2)) ///
       legend(pos(2) ring(0) col(1) region(lwidth(none)) order(  1 "Factor: Competitors' prices" 2 "Own-price expected change (RHS)" ) ) ///
	   title("Panel D") ///
	   graphregion(color(white)) bgcolor(white) ///
	    xsize(5) ysize(4) ///
	   	name(fig4, replace) 
		
	   
graph combine fig1 fig2 fig3 fig4, ///
	rows(2) imargin(tiny) ///
	graphregion(color(white)) ///
	    xsize(14) ysize(8) ///
		name(comb2, replace)

